package com.hwangjr.rxbus.entity;

import java.lang.reflect.InvocationTargetException;

/**
 * Event
 */
abstract class Event {
    /**
     * Throw {@link RuntimeException} with given message and cause lifted from an {@link
     * InvocationTargetException}. If the specified {@link InvocationTargetException} does not have a
     * cause, neither will the {@link RuntimeException}.
     * @param msg A brief description for Exception.
     * @param exc InvocationTargetException
     */

    public void throwRuntimeException(String msg, InvocationTargetException exc) {
        throwRuntimeException(msg, exc.getCause());
    }

    /**
     * Throw {@link RuntimeException} with given message and cause lifted from an {@link
     * InvocationTargetException}. If the specified {@link InvocationTargetException} does not have a
     * cause, neither will the {@link RuntimeException}.
     * @param msg A brief description for Exception
     * @param exc Throwable
     */
    public void throwRuntimeException(String msg, Throwable exc) {
        Throwable cause = exc.getCause();
        if (cause != null) {
            throw new RuntimeException(msg + ": " + cause.getMessage(), cause);
        } else {
            throw new RuntimeException(msg + ": " + exc.getMessage(), exc);
        }
    }

}